/**
 * Yolema.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package org.grayrabbit.pay.core.service.system.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.grayrabbit.pay.core.model.pages.PageList;
import org.grayrabbit.pay.core.model.pages.PageTools;
import org.grayrabbit.pay.core.model.utils.AppSystemUtil;
import org.grayrabbit.pay.core.service.system.AppSystemService;
import org.grayrabbit.pay.core.dao.system.AppSystemDao;
import org.grayrabbit.pay.core.model.entity.system.AppSystem;

/**
 * 
 * 
 * @author liyd
 * @version $Id: AppSystemServiceImpl.java, v 0.1 Fri Jun 01 11:14:01 CST 2012 liyd Exp $
 */
@Component
public class AppSystemServiceImpl implements AppSystemService {

    @Autowired
    private AppSystemDao appSystemDao;

    /**
     * 查询业务对象列表
     * 
     * @param appSystem
     * @return
     */
    public PageList<AppSystem> queryPageList(AppSystem appSystem) {

        PageTools pageTools = new PageTools();
        pageTools.setPage(appSystem.getPageNum());
        pageTools.setItemsPerPage(appSystem.getPageSize());

        Map<String, Object> params = new HashMap<String, Object>();

        params.put("query", appSystem);
        params.put("startRow", pageTools.getBeginIndex());
        params.put("pageSize", pageTools.getItemsPerPage());

        pageTools.setItems(appSystemDao.queryCount(params));

        PageList<AppSystem> pageList = new PageList<AppSystem>();
        pageList.addAll(appSystemDao.queryPageList(params));
        pageList.setPageTools(pageTools);

        return pageList;

    }



    /**
     * 根据Id得到实体对象
     * 
     * @param id
     * @return
     */
    public AppSystem getById(Long id) {

        return appSystemDao.getById(id);
    }

    /**
     * 根据id批量删除
     * 
     * @param idArray
     */
    public void deleteBatchById(Long[] idArray) {
        appSystemDao.deleteBatchById(idArray);
        AppSystemUtil.putAllAppSystem(this.findAll());
    }

    /**
     * 查询所有对象
     * 
     * @return
     */
    public List<AppSystem> findAll() {
        return appSystemDao.findAll();
    }

    /**
     * 添加一个对象
     * 
     * @param appSystem
     */
    public void insert(AppSystem appSystem) {

        appSystemDao.save(appSystem);
        AppSystemUtil.removeAppSystem(appSystem);

    }

    public int getCountByAppCode(String appCode) {
        return appSystemDao.getCountByAppCode(appCode);
    }

    /**
     * 更新一个对象
     * 
     * @param appSystem
     * @return
     */
    public int update(AppSystem appSystem) {
        AppSystemUtil.putAppSystem(appSystem);
        return appSystemDao.update(appSystem);

    }

    public int changeStatus(AppSystem appSystem) {

        return appSystemDao.changeStatus(appSystem);

    }

    /**
     * 删除一个对象
     * 
     * @param appSystem
     */
    public void delete(AppSystem appSystem) {
        AppSystemUtil.removeAppSystem(appSystem);
        appSystemDao.delete(appSystem);
    }

}
